#include "TileMap.h"
TileMap::TileMap():
m_iMapScaleH(1),
m_iMapScaleW(1),
PosicionInicial(0,0,0)
{}
void TileMap::Draw(Renderer *m_pkRenderer)
{
	for(m_iTileMapIter = m_iTileMap.begin();m_iTileMapIter != m_iTileMap.end();m_iTileMapIter++)
	{
		std::vector<int*> Layer = m_iTileMapIter->second;

		for(int i=0;i<m_CountTileH;i++)
		{
			for(int j=0;j<m_CountTileW;j++)
			{
					Tile * s = m_mTilesUsed[Layer[i][j]];
					float px = PosicionInicial.x+(j*s->GetScaleW())+(m_iMapScaleW*s->GetScaleW()); 
					float py = PosicionInicial.y-(i*s->GetScaleH())+(m_iMapScaleH*s->GetScaleH());
					float pz = 0;		
					s->SetPos(px,py,pz);
					if(Layer[i][j]!=-1)
						s->Draw(m_pkRenderer);
				
			}
		}
	}
}
void TileMap::setScaleTileMap(float p_fWidth, float p_fHeight)
{
	for(m_iTileMapIter = m_iTileMap.begin();m_iTileMapIter != m_iTileMap.end();m_iTileMapIter++)
	{
		std::vector<int*> Layer = m_iTileMapIter->second;

		for(int i=0;i<m_CountTileH;i++)
		{
			for(int j=0;j<m_CountTileW;j++)
			{
				{
					Tile * s = m_mTilesUsed[Layer[i][j]];
					s->SetScale(p_fWidth,p_fHeight);
				}
			}
		}	
	}
}
void TileMap::getRowCol(int Pos, int Cols, int *Col, int* Row)
{
	int AuxCol=0;
	int AuxRow=0;

	while (Pos >= Cols)
	{
		Pos -= Cols;
		AuxRow ++;
	}
	AuxCol = Pos;

	*Col = AuxCol;
	*Row = AuxRow;
}